package com.bestcem.xm.user.dao.impl;

import com.alibaba.excel.util.StringUtils;
import com.bestcem.xm.user.dao.UserMfaSettingDao;
import com.bestcem.xm.user.dao.mapper.UserMfaSettingMapper;
import com.bestcem.xm.user.entity.pojo.UserMfaSettingDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.UserMfaSettingConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * 用户登录安全验证信息 Dao
 *
 * @author panyun <yun.pan@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/10 18:10
 */
@Repository
public class UserMfaSettingDaoImpl implements UserMfaSettingDao {

    @Resource
    private UserMfaSettingConvert userMfaSettingConvert;

    @Resource
    private UserMfaSettingMapper userMfaSettingMapper;

    @Override
    public UserMfaSettingDO getMfaSettingByOrgId(String orgId) {
        return userMfaSettingConvert.mysql2Do(userMfaSettingMapper.selectByOrgId(orgId));
    }

    @Override
    public int updateByPrimaryKeySelective(UserMfaSettingDO userMfaSettingDO) {
        return userMfaSettingMapper.updateByPrimaryKeySelective(userMfaSettingConvert.do2Mysql(userMfaSettingDO));
    }

    @Override
    public int insertSelective(UserMfaSettingDO userMfaSettingDO) {
        if (StringUtils.isBlank(userMfaSettingDO.getId())) {
            userMfaSettingDO.setId(DataBaseUtil.generateId());
        }
        DataBaseUtil.setCreateAndUpdateTime(userMfaSettingDO);
        return userMfaSettingMapper.insertSelective(userMfaSettingConvert.do2Mysql(userMfaSettingDO));
    }
}
